package sis.studentinfo;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-07-26 09:30
 * @notify
 * @version 1.0
 */

import sis.db.DataFile;

import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

//存放学生集合
public class StudentDirectory implements Serializable {
    private static final String DIR_BASENAME = "studentDir";

    //存储文件类
    private DataFile db;

    //创建存储文件类
    public StudentDirectory() throws IOException {
        //此时会创建一个读写流
        db = DataFile.open(DIR_BASENAME);
    }



    //添加学生,key为学生的id,值为学生
    public void add(Student student) throws IOException {
        db.add(student.getId(), student);
    }

    //通过学生id获取学生信息
    public Student findById(String id)throws IOException {
        return (Student) db.findBy(id);
    }

    //关闭流
    public void close() throws IOException {
        db.close();
    }

    //删除所有文件
    public void remove()throws IOException {
        db.deleteFiles();
    }
}
